//
//  ZJTabBarBurron.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/2.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJTabBarBurron.h"
#import "UIView+Extension.h"
@interface ZJTabBarBurron ()
{
    UIImage *_normalImage;
    UIImage *_selectedImage;
    NSString *_normalTitle;
    NSString *_selectedTitle;
    UIColor *_normalTitleColor;
    UIColor *_selectedTitleColor;
}
@end
@implementation ZJTabBarBurron

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.imageView];
        [self addSubview:self.titleLabel];
        self.userInteractionEnabled = YES;
        //单击手势
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(action_gesture:)];
        [self addGestureRecognizer:tapGesture];
        
    }
    return self;
}

#pragma mark - 点击事件
- (void)action_gesture:(UIGestureRecognizer *)sender{
    self.selected = !self.selected;
    if (self.delegate) {
        [self.delegate action_customButtonClick:self];
    }
}

#pragma mark - 赋值
- (void)setSelected:(BOOL)selected{
    if (!selected) {//CustomButtonStateNormal
        self.imageView.image = _normalImage;
        self.titleLabel.text = _normalTitle;
        self.titleLabel.textColor = _normalTitleColor;
        
    }else{//CustomButtonStateSelected
        self.imageView.image = _selectedImage;
        self.titleLabel.text = _selectedTitle;
        self.titleLabel.textColor = _selectedTitleColor;
        if (_selectedTitle == nil) {
            self.titleLabel.text = _normalTitle;
        }
    }
}


- (void)setImage:(UIImage *)image forState:(ZJTabBarBurronState)State{
    if (State == ZJTabBarBurronStateNormal) {
        _normalImage = image;
    }else if(State == ZJTabBarBurronStateSelected){
        _selectedImage = image;
    }
}

- (void)setTitle:(NSString *)title forState:(ZJTabBarBurronState)State{
    if (State == ZJTabBarBurronStateNormal) {
        _normalTitle = title;
    }else if(State == ZJTabBarBurronStateSelected){
        _selectedTitle = title;
    }
}


- (void)setTitleColor:(UIColor *)titleColor forState:(ZJTabBarBurronState)State{
    if (State == ZJTabBarBurronStateNormal) {
        _normalTitleColor = titleColor;
    }else if(State == ZJTabBarBurronStateSelected){
        _selectedTitleColor = titleColor;
    }
}





#pragma mark - Setter
#pragma mark - Getters
- (UIImageView *)imageView{
    if (_imageView == nil){
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.width / 2 - 11, 8, 22 , 22)];
        _imageView.contentMode = UIViewContentModeCenter;
    }
    return _imageView;
}

- (UILabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.height - 16, self.width, 16)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:10];
    }
    return _titleLabel;
}



@end
